<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>

    import Edit from "./../edit/index";
    export default {
        mixins: [Vue.prototype.$vFN.Mixins.Base,Vue.prototype.$vFN.Mixins.Page, Vue.prototype.$vFN.Mixins.Table],
        data() {
            return {
                appWindow: window,
                // 页面接口地址
                apiUrl: {
                    list: "store/comment/pageComment",
                    // delete: "mall-site-portal/product-brand/delete",
                },
                // 表格查询数据
                mixinTable_tableSearchData: {
                    commentContextType: '', // 	评论内容类型 0仅文字 1有图 2有视频
                    commentType: '', // 评价方式类型 0主动 1自动
                    isShow: '', // 是否显示 0 否 1是
                    isReply: '', // 	回复方式类型 0 未回复 1已回复
                    isSelected: '', // 	精选类型 0 未精选 1已精选

                    deliveryLevel: '', // 配送等级 1-5 大值好评
                    serviceLevel: '',  // 服务等级 1-5 大值好评
                    commentLevel: '', // 评价等级 1-5 大值好评
                },
                // 表格数据
                tableData: [],
                // 表格数据删除展示结构
                tableDeleteConfig: {
                    columns: [{
                            label: "品牌名称",
                            prop: "name",
                            type: ""
                        },
                        {
                            label: "绑定商品数",
                            prop: "productCount",
                            type: ""
                        },
                    ],
                },

                textarea: '',
                currentId: '',
                dialogVisible: false

            };
        },
        methods: {
            rateType(v){
                v -=0;
                if(v==5){
                    return "danger"
                }
                if(v>2){
                    return "warning"
                }
                
                return "info"
            },
            // 设置全部精选
            setAllComment() {
                let _ids = []
                for (let arr of this.mixinTable_selectTableData) {
                    if (arr.isSelected === 0) {
                        _ids.push(arr.id)
                    }
                }
                this.setMethod(_ids, 0)
            },
            // 取消全部精选
            cancelSetAllComment() {
                let _ids = []
                for (let arr of this.mixinTable_selectTableData) {
                    if (arr.isSelected === 1) {
                        _ids.push(arr.id)
                    }
                }
                this.setMethod(_ids, 1)
            },

            // 设置精选
            setComment(_data) {
                console.log(_data, _data.isSelected)
                let _ids = []
                let _isSeleted = _data.isSelected
                _ids.push(_data.id)
                this.setMethod(_ids, _isSeleted)
            },

            // 精选的方法
            setMethod (_ids, _isSeleted) {
                console.log(_ids, _isSeleted)
                this.$confirm(_isSeleted === 0 ? '确认设置为精选吗?' : '确认取消精选吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(async () => {
                    let _res = await this.$vFN.Http.post({
                        url: "store/comment/batchCommentSelected",
                        data: {
                            commentIdLst: _ids,
                            isSelected: _isSeleted === 0 ? 1 : 0 // 精选类型 0 未精选 1已精选
                        },
                    }, window);
                    if (_res._ok) {
                        console.log(_res)
                        this.$vFN.Tools.messageSuccess("操作成功")
                        this.init()
                    }
                }).catch(() => {
                    // this.$vFN.Tools.messageError("操作失败")
                })
            },

            // 隐藏所有评论
            hideAllComment () {
                let _ids = []
                for (let arr of this.mixinTable_selectTableData) {
                    if (arr.isShow === 1) {
                        _ids.push(arr.id)
                    }
                }
                this.hideMethod(_ids, 1)
            },

            // 取消隐藏全部评论
            cancelHideAllComment () {
                let _ids = []
                for (let arr of this.mixinTable_selectTableData) {
                    if (arr.isShow === 0) {
                        _ids.push(arr.id)
                    }
                }
                this.hideMethod(_ids, 0)
            },

            // 隐藏评论
            hideComment(_data) {
                let _isShow = _data.isShow
                let _ids = []
                _ids.push(_data.id)
                this.hideMethod(_ids, _isShow)
            },

            // 隐藏的方法
            hideMethod (_ids, _isShow) {
                console.log(_ids, _isShow)
                this.$confirm(_isShow === 1 ? '确认隐藏该评论吗?' : '确认取消隐藏该评论吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(async () => {
                    let _res = await this.$vFN.Http.post({
                        url: "store/comment/batchCommentHide",
                        data: {
                            commentIdLst: _ids,
                            isShow: _isShow === 0 ? 1 : 0  // 是否显示 0 否 1是
                        },
                    }, window);
                    if (_res._ok) {
                        console.log(_res)
                        this.$vFN.Tools.messageSuccess("操作成功")
                        this.init()
                    }
                }).catch(() => {
                    // this.$vFN.Tools.messageError("操作失败")
                })
            },

            // 打开添加/修改
            editBoxOpen(params_) {
                // console.log(params_)
                Edit.init({
                    mixinEdit_parent:this,
                    params:params_
                })
            },
            // 初始化
            async init() {
                this.mixinTable_refreshData();
            },

        },
        mounted() {
            this.init();

        },
        activated() {},
    };
</script>
